<?php

/**
 * This is the model class for table "Account".
 *
 * The followings are the available columns in table 'Account':
 * @property string $id_contract
 * @property string $login
 * @property string $password
 * @property string $new_password
 * @property string $new_password2
 */
class Account extends CActiveRecord
{
	public $old_password = "";
	public $new_password = "";
	public $new_password2 = "";
	/**
	 * Returns the static model of the specified AR class.
	 * @return HardSettings the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Account';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_contract', 'length', 'max'=>11),
			array('login', 'length', 'max'=>20),
			array('password, old_password,new_password2,new_password', 'length','min'=>3, 'max'=>40),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_contract, dns_name, login, password', 'safe', 'on'=>'search'),
			array('password, old_password,new_password2,new_password','required'),
			array('old_password', 'compare', 'compareAttribute'=>'password'),
			array('new_password', 'compare', 'compareAttribute'=>'new_password2'),
			array('password, old_password,new_password2,new_password', 'match', 'pattern'=>'/^[a-z0-9\_]+$/i'),
			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_contract' => 'Id contract',
			'login' => 'Логин',
			'password' => 'Пароль',
			'old_password' => 'Текущий пароль',
			'new_password' => 'Новый пароль',
			'new_password2' => 'Повторите новый пароль',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_contract',$this->id_contract,true);
		$criteria->compare('login',$this->login,true);
		$criteria->compare('password',$this->password,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}

	public function primaryKey()
	{
		return "id_contract"; 
	}
}